home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / instance.h < prev    next >
C/C++ Source or Header  |  1999-01-01  |  4KB  |  142 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  INSTANCE.H - Instance Class
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.5
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #ifndef _INSTANCE_H
  39. #define _INSTANCE_H
  40.  
  41. #include "surface3.h"
  42.  
  43. class Instance          // Instance (also entity)
  44. {
  45.   private:
  46.     Surface3 *pshead;   // Surface list head pointer
  47.     Vertex3 *pvhead;    // Vertex list head pointer
  48.     Instance *pnext;    // Next instance pointer
  49.  
  50.     double max_x, max_y, max_z;
  51.     double min_x, min_y, min_z;
  52.  
  53.   public:
  54.     Instance( Vertex3 *pv, Surface3 *ps )
  55.     {
  56.       pvhead = pv;
  57.       pshead = ps;
  58.       pnext = NULL;
  59.  
  60.     }
  61.  
  62.     ~Instance()
  63.     {
  64.       Surface3 *psnext;
  65.       Surface3 *ps = pshead;
  66.       Vertex3 *pvnext;
  67.       Vertex3 *pv = pvhead;
  68.  
  69.       // Delete surfaces
  70.       while (ps != NULL)
  71.       {
  72.         psnext = ps->GetNext();
  73.         delete ps;
  74.         ps = psnext;
  75.       }
  76.  
  77.       // Delete vertices
  78.       while (pv != NULL)
  79.       {
  80.         pvnext = pv->GetNext();
  81.         delete pv;
  82.         pv = pvnext;
  83.       }
  84.     }
  85.  
  86.     Instance *GetNext() { return pnext; }
  87.     Surface3 *GetSurfPtr() { return pshead; }
  88.     Vertex3 *GetVertPtr() { return pvhead; }
  89.     void SetNext( Instance *pn ) { pnext = pn; }
  90.     void SetSurfPtr( Surface3 *ps ) { pshead = ps; }
  91.     void SetVertPtr( Vertex3 *pv ) { pvhead = pv; }
  92.     double GetMax_X() { return max_x; }
  93.     double GetMax_Y() { return max_y; }
  94.     double GetMax_Z() { return max_z; }
  95.     double GetMin_X() { return min_x; }
  96.     double GetMin_Y() { return min_y; }
  97.     double GetMin_Z() { return min_z; }
  98.     void CalcExtents()
  99.     {
  100.       double vx,vy,vz;
  101.       Vertex3 *pvert;
  102.  
  103.       // Initialize extents
  104.       max_x = max_y = max_z = -MAX_VALUE;
  105.       min_x = min_y = min_z = MAX_VALUE;
  106.  
  107.       // Walk the vertex list
  108.       pvert = pvhead;
  109.       while (pvert != NULL)
  110.       {
  111.  
  112.         // Get vertex co-ordinates
  113.         vx = pvert->GetPosn().GetX();
  114.         vy = pvert->GetPosn().GetY();
  115.         vz = pvert->GetPosn().GetZ();
  116.  
  117.         // Update x-axis extents
  118.         if (vx > max_x)
  119.           max_x = vx;
  120.         if (vx < min_x)
  121.           min_x = vx;
  122.  
  123.         // Update y-axis extents
  124.         if (vy > max_y)
  125.           max_y = vy;
  126.         if (vy < min_y)
  127.           min_y = vy;
  128.  
  129.         // Update z-axis extents
  130.         if (vz > max_z)
  131.           max_z = vz;
  132.         if (vz < min_z)
  133.           min_z = vz;
  134.  
  135.         pvert = pvert->GetNext();
  136.       }
  137.     }
  138. };
  139.  
  140. #endif
  141.  
  142.